# Given a string,
# find the length of the longest substring without repeating characters.
# eg:
# Input: "abcabcbb"
# Output: 3
# Explanation: The answer is "abc", with the length of 3.

class Solution:
    def lengthOfLongestSubstring(self, s):
        if len(s) == 0:
            return 0

        if len(s) == 1:
            return 1

        j = 1
        max_len = 0
        startPos = 0
        endPos = 1
        isSame = False

        while j < len(s):

            k = 0
            for k in range(startPos, endPos):
                if s[j] == s[k]:
                    isSame = True
                    break

            if isSame is False:  # 此时在滑动窗口中没有重复元素
                endPos += 1
            else:  # 若出现重复元素,将位置靠前的那个重复元素前面的字符串丢掉，将窗口继续向后滑动。
                startPos = k + 1
                endPos = j + 1
                isSame = False

            length = endPos - startPos  # 原来的无重复结点的字符串长度
            max_len = max(length, max_len)
            j += 1

        # print(max_len)
        return max_len


solution = Solution()
solution.lengthOfLongestSubstring("")

# abcabcbb -> bcabcbb
# a->
# ab - >abc ->

# pwwkew --> wke
# abcabcbb--> abc
# dvdf --> vdf
# cdd --> cd
